package com.example.backblog.controller.blog;

import com.alibaba.fastjson.JSONObject;
import com.example.backblog.apijson.DemoParser;
import com.example.backblog.dao.TagMapper;
import com.example.backblog.entity.blog.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/tag")
public class TagController {
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    @Autowired
    private TagMapper tagMapper;
    @PostMapping("/add")
    public JSONObject addOne(@RequestBody Tag tag){
        int insert = tagMapper.insert(tag);
        // 同时修改缓存
        redisTemplate.delete("demo:listAll1::SimpleKey []");
        return DemoParser.newSuccessResult();
    }
    @PostMapping("/update")
    public JSONObject updateOne(@RequestBody Tag tag){
        int update = tagMapper.updateById(tag);
        redisTemplate.delete("demo:listAll1::SimpleKey []");
        return DemoParser.newSuccessResult();
    }
}
